package com.hmyd.hmyd_android.adapter;

import java.util.List;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.dto.JfMallAddressDto;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

/**
 * 地址布局填充管理
 * @author wangk
 *
 */
public class JfMallAddAdapter extends BaseAdapter {
	
	private List<JfMallAddressDto> data;
	private Context context;
	private View lastView;
	
	public JfMallAddAdapter(List<JfMallAddressDto> data, Context context) {
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position%data.size());
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.view_adress_item, null);
			holder.name = (TextView) convertView.findViewById(R.id.recName);
			holder.cellPhone = (TextView) convertView.findViewById(R.id.recMPhone);
			holder.fixPhone = (TextView) convertView.findViewById(R.id.recFPhone);
			holder.address = (TextView) convertView.findViewById(R.id.recAdd);
			holder.isDefaultCB = (CheckBox)convertView.findViewById(R.id.defaultAddCheck);
			holder.Adedit = (Button)convertView.findViewById(R.id.addEdit);
			holder.Addelete = (Button)convertView.findViewById(R.id.addDelete);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		JfMallAddressDto dto = data.get(position);
		holder.name.setText(dto.addressee);
		holder.cellPhone.setText(dto.cellPhoneNumber);
		holder.fixPhone.setText(dto.fixedTelephone);
		holder.address.setText(dto.province+dto.city+dto.area+dto.address);
		holder.isDefaultCB.setChecked(dto.isDefault);
		// 编辑按钮
		holder.Adedit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		// 删除按钮
		holder.Addelete.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		return convertView;
	}
	
	class ViewHolder{
		TextView name;
		TextView cellPhone;
		TextView fixPhone;
		TextView address;
		CheckBox isDefaultCB;
		Button Adedit;
		Button Addelete;
	}

}
